package com.skynet.app.api.auth.controller;

import com.skynet.app.api.auth.annotation.Log;
import com.skynet.app.api.auth.dto.UserAuthDTO;
import com.skynet.app.api.auth.service.UserAuthService;
import com.skynet.app.api.auth.util.ResultVOUtil;
import com.skynet.app.api.auth.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.skynet.app.api.auth.enums.ResultEnum.*;

/**
 * @author Skynet
 * @date 2017年11月23日 12:00
 */
@RestController
@RequestMapping("/api")
public class UserAuthController {

    @Autowired
    private UserAuthService userAuthService;

    @PostMapping("/login")
    @Log("用户登录")
    public ResultVO login(@RequestBody UserAuthDTO userAuthDTO) {
        return ResultVOUtil.success(userAuthService.login(userAuthDTO), LOGIN_SUCCESS.getMsg());
    }

    @PostMapping("/register")
    @Log("用户注册")
    public ResultVO register(@RequestBody UserAuthDTO userAuthDTO) {
        userAuthService.register(userAuthDTO);
        return ResultVOUtil.success(REGISTER_SUCCESS.getMsg());
    }

    @DeleteMapping("/logout")
    @Log("用户注销")
    public ResultVO logout() {
        userAuthService.logout();
        return ResultVOUtil.success(LOGOUT_SUCCESS.getMsg());
    }

    @PostMapping("/request-pass")
    @Log("取回密码")
    public ResultVO requestPass(@RequestBody UserAuthDTO userAuthDTO) {
        userAuthService.requestPass(userAuthDTO);
        return ResultVOUtil.success(REQUEST_PASSWORD_SUCCESS.getMsg());
    }

    @PutMapping("/reset-pass")
    @Log("重置密码")
    public ResultVO resetPass(@RequestBody UserAuthDTO userAuthDTO) {
        userAuthService.resetPass(userAuthDTO);
        return ResultVOUtil.success(RESET_PASSWORD_SUCCESS.getMsg());
    }

}
